const Controller = require('egg').Controller;

class AddController extends Controller {
    async index() {
        const {
            ctx
        } = this;
        var db = this.app.mongodb;
        console.log(ctx);
        var { username, name, imgUrl, money, remarks, date } = ctx.request.body
        console.log(username);
        // console.log(ctx.params);
        var res = await db.collection("user").find({ username }).toArray();
        console.log(res)
        res[0].detail.forEach(item => {
            if (name == item.name) {
                item.Statistics.push({
                    name,
                    imgUrl,
                    money: Number(money),
                    remarks,
                    date: Number(date),
                })
            }
        })
        var arr = await db.collection("user").updateOne({ username }, { $set: { detail: res[0].detail } });
        ctx.body = arr
    }
}

module.exports = AddController;